<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 15-1-13
 * Time: 下午3:46
 */
namespace Admin\Model;
use Think\Model\RelationModel;

class CharModel extends RelationModel {
    //关联表
    protected $_link = array(
        'plant' => array(
            'mapping_type'   => self::HAS_ONE,
            'foreign_key'    => 'id',
            'class_name'     => 'plant',
            'mapping_key'    => 'ev_plant_id',
            'mapping_name'  => 'plantinfo'
        ),
        'charstate' => array(
            'mapping_type'   => self::HAS_MANY,
            'foreign_key'    => 'charID',
            'class_name'     => 'charstate',
            'mapping_key'    => 'charID',
            'mapping_name'  => 'charstateinfo'
        ),
    );
    //备用
    public function getKey(){
       $char = M("char")->select();
       foreach($char as $k=>$v){
           $key_link = substr($v['key_link'],0,12);
           $plant = M("plant")->where("station_key='".$key_link."'")->find();
           $char[$k]['plantinfo'] = $plant;
       }
       return $char;
    }
}